AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Initialize()
	self.Entity:SetModel("models/weapons/w_umd.mdl");
	self.Entity:PhysicsInit(SOLID_VPHYSICS);
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS);
	self.Entity:SetSolid(SOLID_VPHYSICS);
	self.Entity:SetCollisionGroup(COLLISION_GROUP_PROJECTILE)
	local phys = self:GetPhysicsObject()
	if phys:IsValid() then
		phys:Wake()
		phys:EnableGravity(false);
	end
	//create a trail
	self.Trail = util.SpriteTrail(self.Entity, 0, Color(255,255,255,255), false, 15, 1, 0.2, 1/(15+1)*0.5, "trails/electric.vmt") 
end

function ENT:Think()
end

function ENT:SpawnFunction(ply, tr)

	if (!tr.Hit) then return end

	local SpawnPos = tr.HitPos + tr.HitNormal * 16;

	local ent = ents.Create("smod_umd");
	ent:SetPos(SpawnPos);
	ent:Spawn();
	ent:Activate();
	ent:SetOwner(ply)
	return ent;
end

function ENT:PhysicsCollide(Data)
	local pos = self.Entity:GetPos() --Get the position of the umd
	local effectdata = EffectData()
	effectdata:SetStart( pos )
	effectdata:SetOrigin( pos )
	effectdata:SetScale( 1 )
	util.Effect( "Explosion", effectdata ) -- effect to blastdamage
	util.BlastDamage( self.Entity, self.Entity:GetOwner(), pos, 230, 90 ) --blastdamge
	if (Data.HitEntity:IsWorld() ) then
	util.Decal("Scorch", Data.HitPos + Data.HitNormal, Data.HitPos - Data.HitNormal) -- paint a decal
	end
	self.Entity:Remove(); --Remove the umd

end 